C1PdfViewer allows you to add a message box to control navigation away from the PDF document. If a user clicks on a link in the PDF file, the application will give them the option to navigate away from the document or to cancel the navigation request.
Note that in this step you will add a PDF file that is included with the ComponentOne Studio for Windows Phone samples, which are by default installed in the Documents folder in the ComponentOne Samples\UWP directory. If you choose, you can instead use another PDF file and adapt the steps.
Complete these steps to create the navigation request:
<c1pdfviewer:C1PdfViewer x:Name="pdfViewer" ViewMode="FitWidth" />
To write the code in Visual Basic:
Imports C1.Xaml.PdfViewer
u
To write the code in C#:
using C1.Xaml.PdfViewer;
Loaded += new RoutedEventHandler(PhoneApp5_Loaded);
pdfViewer.RequestNavigate += (s, e) =>
{
var result = MessageBox.Show("The document is requesting to navigate to " + e.Uri, "Navigate", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
// navigate to urls loading web browser control
WebBrowser browser = new WebBrowser();
browser.Navigate(e.Uri);
LayoutRoot.Children.Clear();
LayoutRoot.Children.Add(browser);
}
};
}
void PhoneApp5_Loaded(object sender, RoutedEventArgs e)
{
var resource = Application.GetResourceStream(new Uri("PhoneApp5;component/C1XapOptimizer.pdf", UriKind.Relative));
pdfViewer.LoadDocument(resource.Stream);
//pdfViewer.PageRendered += (s2, e2) =>
{
//if (e2.TotalRenderedPages >= 2)
{
pdfViewer.Visibility = System.Windows.Visibility.Visible;
}
}
}
}
}
To write the code in Visual Basic:
Loaded = (Loaded + AddressOf Me.PhoneApp5_Loaded)
pdfViewer.RequestNavigate = (pdfViewer.RequestNavigate + s)
,e
Unknown=Greater{Dim result As var = MessageBox.Show(("The document is requesting to navigate to " + e.Uri), "Navigate", MessageBoxButton.OKCancel)
If (result = MessageBoxResult.OK) Then
' navigate to urls loading web browser control
Dim browser As WebBrowser = New WebBrowser
browser.Navigate(e.Uri)
LayoutRoot.Children.Clear
LayoutRoot.Children.Add(browser)
End If
UnknownUnknownUnknownUnknown
Private Sub PhoneApp5_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim resource As var = Application.GetResourceStream(New Uri("PhoneApp5;component/C1XapOptimizer.pdf", UriKind.Relative))
pdfViewer.LoadDocument(resource.Stream)
'pdfViewer.PageRendered += (s2, e2) =>
'if (e2.TotalRenderedPages >= 2)
pdfViewer.Visibility = System.Windows.Visibility.Visible
End Sub
To write the code in C#:
C# Copy CodeLoaded += new RoutedEventHandler(PhoneApp5_Loaded);
pdfViewer.RequestNavigate += (s, e) =>
{
var result = MessageBox.Show("The document is requesting to navigate to " + e.Uri, "Navigate", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
// navigate to urls loading web browser control
WebBrowser browser = new WebBrowser();
browser.Navigate(e.Uri);
LayoutRoot.Children.Clear();
LayoutRoot.Children.Add(browser);
}
};
}
void PhoneApp5_Loaded(object sender, RoutedEventArgs e)
{
var resource = Application.GetResourceStream(new Uri("PhoneApp5;component/C1XapOptimizer.pdf", UriKind.Relative));
pdfViewer.LoadDocument(resource.Stream);
//pdfViewer.PageRendered += (s2, e2) =>
{
//if (e2.TotalRenderedPages >= 2)
{
pdfViewer.Visibility = System.Windows.Visibility.Visible;
}
}
}
}
}